document.querySelector(".fanhui").onclick = function () {
    location.href = "./index.html"
}

// 拿dom元素
let OInuts = document.getElementsByTagName('input')
console.log(OInuts);
let username = getCookie('username')
let userid = getCookie('userid')
let userphone = getCookie('userphone')
let userpass = getCookie('userpass')
let userpass2 = getCookie('userpass2')


function commit() {
    OInuts[0].value = username
    OInuts[1].value = userphone
    OInuts[2].value = userpass
    OInuts[3].value = userpass2
    // if(OInuts[0].value != username || OInuts[1].value != userphone || OInuts[2].value != userpass || OInuts[4].value != userpass2){
    //     clicuser()
    // }

}

function clicuser() {
    OInuts[4].onclick = function () {
        console.log("1");
        ajaxUsePromise02({
            url: "http://localhost:3000/vips",
            method: "get",
        }).then(res => {
            res.forEach(element => {
                console.log(element);
                if (element.username == username && element.userphone == userphone && element.userpass == userpass && element.userpass2 == userpass2) {
                    console.log(element);
                    geng()
                }
            });
        })
    }
}

function geng() {
    ajaxUsePromise02({
        url: `http://localhost:3000/vips/${userid}`,
        method: "PUT",
        data: `username=${OInuts[0].value}&userphone=${OInuts[1].value}&userpass=${OInuts[2].value}&userpass2=${OInuts[3].value}`
    }).then(res => {
        console.log(res);
        saveCookie("userid", userid, 7);
        saveCookie("username", OInuts[0].value, 7);
        saveCookie("userphone", OInuts[1].value, 7);
        saveCookie("userpass", OInuts[2].value, 7);
        saveCookie("userpass2", OInuts[3].value, 7);
        location.href = "./user.html"
    })
}




window.onload = function () {
    commit();
    clicuser()
}